#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
int main() {
	int T;
	LL st,en;
	cin>>T;
	while (T--) {
		cin>>st>>en;
		LL pre, nex;
		LL tmp=sqrt(st);
		if (tmp*tmp==st) pre=tmp-1;
		else pre=tmp;
		tmp=sqrt(en);
		nex=tmp;
		cout<<nex-pre<<endl;
	}
	return 0;
} 
